package sample.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import javax.ejb.EJB;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CodesController extends HttpServlet {

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        String urlDispatcher = "";
        try {
            String action = request.getParameter("action");
            if (action == null) {
                urlDispatcher = "reqCodes.jsp";
                RequestDispatcher rd = request.getRequestDispatcher(urlDispatcher);
                rd.forward(request, response);
                
            } else if (action.equals("X")) {
                out.println("<html>");
                out.println("<head>");
                out.println("<title>Result . . .</title>");            
                out.println("</head>");
                out.println("<body><table>");
                out.println("</table></body>");
                out.println("</html>");

            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {            
            out.close();
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    public String getServletInfo() {
        return "Short description";
    }
}
